package com.glory.dmegcpda.adapter

import android.widget.ToggleButton
import com.chad.library.adapter.base.BaseQuickAdapter
import com.glory.dmegcpda.R
import com.glory.dmegcpda.base.DataBindBaseViewHolder
import com.glory.dmegcpda.bean.KeepInfoEntity
import com.glory.dmegcpda.databinding.ItemKeepInfoListBinding

/**
 * FileName: CheckInfoAdapter
 * Author: XJH
 * Date: 2021/10/21 16:33
 * Description:
 * History:
 */
class   KeepInfoAdapter(data: List<KeepInfoEntity.PmsSheetDataEntity.CheckDataEntity>) :
    BaseQuickAdapter<KeepInfoEntity.PmsSheetDataEntity.CheckDataEntity, DataBindBaseViewHolder>(
        R.layout.item_keep_info_list,
        data as MutableList<KeepInfoEntity.PmsSheetDataEntity.CheckDataEntity>
    ) {
    override fun convert(helper: DataBindBaseViewHolder, item: KeepInfoEntity.PmsSheetDataEntity.CheckDataEntity) {
        val itemKeepInfoListBinding : ItemKeepInfoListBinding = helper.getDataBinding() as ItemKeepInfoListBinding
        itemKeepInfoListBinding.keepInfoItem = item
        val tbButton : ToggleButton = helper.getView(R.id.tbButton)
        if (item.RESERVED1 == "Y"){
            tbButton.isChecked = true
        }
        tbButton.setOnCheckedChangeListener { _, isChecked ->
            item.RESERVED1 = if (isChecked) "Y" else "N"
        }
        itemKeepInfoListBinding.executePendingBindings()
    }
}